package cn.cvs.service.supplier;

import cn.cvs.dao.supplier.SupplierMapper;
import cn.cvs.pojo.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired //Resource
    private SupplierMapper supplierMapper;
    @Override
    public List<Supplier> getList() {
        try {
            return supplierMapper.selectSupplierList();
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public List<Supplier> selectSupplierNameList(Supplier supplier) {
        try {
            return supplierMapper.selectSupplierNameList(supplier);
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int add(Supplier supplier) {
        int result=0;
        try {
            if (supplierMapper.add(supplier)==1){
                result=1;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int del(int id) {
        int result=0;
        try {
            if (supplierMapper.del(id)==1){
                result=1;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int upd(Supplier supplier) {
        int result=0;
        try {
            if (supplierMapper.upd(supplier)==1){
                result=1;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    public SupplierMapper getSupplierMapper() {
        return supplierMapper;
    }

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }
}
